<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>Store | Redux 中文文档 Join the chat at https://gitter.im/camsong/redux-in-chinese</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.3.3">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-edit-link/plugin.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-prism/prism.css">
        
    
    

        
    
    
    <link rel="next" href="../../docs/api/combineReducers.html" />
    
    
    <link rel="prev" href="../../docs/api/createStore.html" />
    

        
    </head>
    <body>
        
        
    <div class="book" data-level="8.2" data-basepath="../.." data-revision="Thu Mar 16 2017 23:41:56 GMT+0800 (CST)">
    

<div class="book-summary">
    <div class="book-search">
        <input type="text" placeholder="Type to search" class="form-control" />
    </div>
    <ul class="summary">
        
        
        
        

        

        
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        自述
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="docs/introduction/index.html">
            
                
                    <a href="../../docs/introduction/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        介绍
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="docs/introduction/Motivation.html">
            
                
                    <a href="../../docs/introduction/Motivation.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        动机
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="docs/introduction/CoreConcepts.html">
            
                
                    <a href="../../docs/introduction/CoreConcepts.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        核心概念
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="docs/introduction/ThreePrinciples.html">
            
                
                    <a href="../../docs/introduction/ThreePrinciples.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        三大原则
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="docs/introduction/PriorArt.html">
            
                
                    <a href="../../docs/introduction/PriorArt.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        先前技术
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="docs/introduction/Ecosystem.html">
            
                
                    <a href="../../docs/introduction/Ecosystem.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        生态系统
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="docs/introduction/Examples.html">
            
                
                    <a href="../../docs/introduction/Examples.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        示例
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="docs/basics/index.html">
            
                
                    <a href="../../docs/basics/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        基础
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="docs/basics/Actions.html">
            
                
                    <a href="../../docs/basics/Actions.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        Action
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="docs/basics/Reducers.html">
            
                
                    <a href="../../docs/basics/Reducers.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        Reducer
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="docs/basics/Store.html">
            
                
                    <a href="../../docs/basics/Store.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        Store
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="docs/basics/DataFlow.html">
            
                
                    <a href="../../docs/basics/DataFlow.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        数据流
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="docs/basics/UsageWithReact.html">
            
                
                    <a href="../../docs/basics/UsageWithReact.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        搭配 React
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="docs/basics/ExampleTodoList.html">
            
                
                    <a href="../../docs/basics/ExampleTodoList.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                        示例：Todo List
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="docs/advanced/index.html">
            
                
                    <a href="../../docs/advanced/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        高级
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="docs/advanced/AsyncActions.html">
            
                
                    <a href="../../docs/advanced/AsyncActions.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        异步 Action
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="docs/advanced/AsyncFlow.html">
            
                
                    <a href="../../docs/advanced/AsyncFlow.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        异步数据流
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="docs/advanced/Middleware.html">
            
                
                    <a href="../../docs/advanced/Middleware.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        Middleware
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="docs/advanced/UsageWithReactRouter.html">
            
                
                    <a href="../../docs/advanced/UsageWithReactRouter.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        搭配 React Router
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="docs/advanced/ExampleRedditAPI.html">
            
                
                    <a href="../../docs/advanced/ExampleRedditAPI.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        示例：Reddit API
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="docs/advanced/NextSteps.html">
            
                
                    <a href="../../docs/advanced/NextSteps.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        下一步
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="docs/recipes/index.html">
            
                
                    <a href="../../docs/recipes/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        技巧
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="docs/recipes/MigratingToRedux.html">
            
                
                    <a href="../../docs/recipes/MigratingToRedux.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        迁移到 Redux
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="docs/recipes/UsingObjectSpreadOperator.html">
            
                
                    <a href="../../docs/recipes/UsingObjectSpreadOperator.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        使用对象展开运算符
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="docs/recipes/ReducingBoilerplate.html">
            
                
                    <a href="../../docs/recipes/ReducingBoilerplate.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        减少样板代码
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="docs/recipes/ServerRendering.html">
            
                
                    <a href="../../docs/recipes/ServerRendering.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        服务端渲染
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="docs/recipes/WritingTests.html">
            
                
                    <a href="../../docs/recipes/WritingTests.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        编写测试
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="docs/recipes/ComputingDerivedData.html">
            
                
                    <a href="../../docs/recipes/ComputingDerivedData.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.6.</b>
                        
                        计算衍生数据
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.7" data-path="docs/recipes/ImplementingUndoHistory.html">
            
                
                    <a href="../../docs/recipes/ImplementingUndoHistory.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.7.</b>
                        
                        实现撤销重做
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.8" data-path="docs/recipes/IsolatingSubapps.html">
            
                
                    <a href="../../docs/recipes/IsolatingSubapps.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.8.</b>
                        
                        子应用隔离
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9" data-path="docs/recipes/StructuringReducers.html">
            
                
                    <a href="../../docs/recipes/StructuringReducers.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.</b>
                        
                        组织 Reducer
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.9.1" data-path="docs/recipes/reducers/PrerequisiteConcepts.html">
            
                
                    <a href="../../docs/recipes/reducers/PrerequisiteConcepts.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.1.</b>
                        
                        Reducer 基础概念
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9.2" data-path="docs/recipes/reducers/BasicReducerStructure.html">
            
                
                    <a href="../../docs/recipes/reducers/BasicReducerStructure.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.2.</b>
                        
                        Reducer 基础结构
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9.3" data-path="docs/recipes/reducers/SplittingReducerLogic.html">
            
                
                    <a href="../../docs/recipes/reducers/SplittingReducerLogic.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.3.</b>
                        
                        Reducer 逻辑拆分
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9.4" data-path="docs/recipes/reducers/RefactoringReducersExample.html">
            
                
                    <a href="../../docs/recipes/reducers/RefactoringReducersExample.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.4.</b>
                        
                        Reducer 重构示例
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9.5" data-path="docs/recipes/reducers/UsingCombineReducers.html">
            
                
                    <a href="../../docs/recipes/reducers/UsingCombineReducers.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.5.</b>
                        
                        `combineReducers` 用法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9.6" data-path="docs/recipes/reducers/BeyondCombineReducers.html">
            
                
                    <a href="../../docs/recipes/reducers/BeyondCombineReducers.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.6.</b>
                        
                        `combineReducers` 进阶
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9.7" data-path="docs/recipes/reducers/NormalizingStateShape.html">
            
                
                    <a href="../../docs/recipes/reducers/NormalizingStateShape.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.7.</b>
                        
                        State 范式化
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9.8" data-path="docs/recipes/reducers/UpdatingNormalizedData.html">
            
                
                    <a href="../../docs/recipes/reducers/UpdatingNormalizedData.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.8.</b>
                        
                        管理范式化数据
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9.9" data-path="docs/recipes/reducers/ReusingReducerLogic.html">
            
                
                    <a href="../../docs/recipes/reducers/ReusingReducerLogic.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.9.</b>
                        
                        Reducer 逻辑复用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9.10" data-path="docs/recipes/reducers/ImmutableUpdatePatterns.html">
            
                
                    <a href="../../docs/recipes/reducers/ImmutableUpdatePatterns.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.10.</b>
                        
                        不可变更新模式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9.11" data-path="docs/recipes/reducers/InitializingState.html">
            
                
                    <a href="../../docs/recipes/reducers/InitializingState.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.11.</b>
                        
                        初始化 State
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="docs/FAQ.html">
            
                
                    <a href="../../docs/FAQ.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        常见问题
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="docs/faq/General.html">
            
                
                    <a href="../../docs/faq/General.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        综合
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="docs/faq/Reducers.html">
            
                
                    <a href="../../docs/faq/Reducers.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        Reducer
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="docs/faq/OrganizingState.html">
            
                
                    <a href="../../docs/faq/OrganizingState.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        组织 State
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="docs/faq/StoreSetup.html">
            
                
                    <a href="../../docs/faq/StoreSetup.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        创建 Store
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="docs/faq/Actions.html">
            
                
                    <a href="../../docs/faq/Actions.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        Action
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="docs/faq/CodeStructure.html">
            
                
                    <a href="../../docs/faq/CodeStructure.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        代码结构
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.7" data-path="docs/faq/Performance.html">
            
                
                    <a href="../../docs/faq/Performance.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.7.</b>
                        
                        性能
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.8" data-path="docs/faq/ReactRedux.html">
            
                
                    <a href="../../docs/faq/ReactRedux.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.8.</b>
                        
                        React Redux
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.9" data-path="docs/faq/Miscellaneous.html">
            
                
                    <a href="../../docs/faq/Miscellaneous.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.9.</b>
                        
                        其它
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="docs/Troubleshooting.html">
            
                
                    <a href="../../docs/Troubleshooting.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        排错
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7" data-path="docs/Glossary.html">
            
                
                    <a href="../../docs/Glossary.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        词汇表
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8" data-path="docs/api/index.html">
            
                
                    <a href="../../docs/api/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                        API 文档
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="8.1" data-path="docs/api/createStore.html">
            
                
                    <a href="../../docs/api/createStore.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.1.</b>
                        
                        createStore
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="8.2" data-path="docs/api/Store.html">
            
                
                    <a href="../../docs/api/Store.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.2.</b>
                        
                        Store
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.3" data-path="docs/api/combineReducers.html">
            
                
                    <a href="../../docs/api/combineReducers.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.3.</b>
                        
                        combineReducers
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.4" data-path="docs/api/applyMiddleware.html">
            
                
                    <a href="../../docs/api/applyMiddleware.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.4.</b>
                        
                        applyMiddleware
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.5" data-path="docs/api/bindActionCreators.html">
            
                
                    <a href="../../docs/api/bindActionCreators.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.5.</b>
                        
                        bindActionCreators
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.6" data-path="docs/api/compose.html">
            
                
                    <a href="../../docs/api/compose.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.6.</b>
                        
                        compose
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="9" data-path="docs/react-redux/index.html">
            
                
                    <a href="../../docs/react-redux/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.</b>
                        
                        react-redux 文档
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="9.1" data-path="docs/react-redux/api.html">
            
                
                    <a href="../../docs/react-redux/api.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.1.</b>
                        
                        API
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.2" data-path="docs/react-redux/troubleshooting.html">
            
                
                    <a href="../../docs/react-redux/troubleshooting.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.2.</b>
                        
                        排错
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="10" >
            
                
                    <a target="_blank" href="https:/github.com/react-guide/redux-tutorial-cn">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.</b>
                        
                        redux-tutorial
                    </a>
            
            
        </li>
    


        
        <li class="divider"></li>
        <li>
            <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                Published with GitBook
            </a>
        </li>
        
    </ul>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header">
    <!-- Actions Left -->
    <a href="#" class="btn pull-left toggle-summary" aria-label="Table of Contents"><i class="fa fa-align-justify"></i></a>
    <a href="#" class="btn pull-left toggle-search" aria-label="Search"><i class="fa fa-search"></i></a>
    
    <div id="font-settings-wrapper" class="dropdown pull-left">
        <a href="#" class="btn toggle-dropdown" aria-label="Font Settings"><i class="fa fa-font"></i>
        </a>
        <div class="dropdown-menu font-settings">
    <div class="dropdown-caret">
        <span class="caret-outer"></span>
        <span class="caret-inner"></span>
    </div>

    <div class="buttons">
        <button type="button" id="reduce-font-size" class="button size-2">A</button>
        <button type="button" id="enlarge-font-size" class="button size-2">A</button>
    </div>

    <div class="buttons font-family-list">
        <button type="button" data-font="0" class="button">Serif</button>
        <button type="button" data-font="1" class="button">Sans</button>
    </div>

    <div class="buttons color-theme-list">
        <button type="button" id="color-theme-preview-0" class="button size-3" data-theme="0">White</button>
        <button type="button" id="color-theme-preview-1" class="button size-3" data-theme="1">Sepia</button>
        <button type="button" id="color-theme-preview-2" class="button size-3" data-theme="2">Night</button>
    </div>
</div>

    </div>

    <!-- Actions Right -->
    
    <div class="dropdown pull-right">
        <a href="#" class="btn toggle-dropdown" aria-label="Share"><i class="fa fa-share-alt"></i>
        </a>
        <div class="dropdown-menu font-settings dropdown-left">
            <div class="dropdown-caret">
                <span class="caret-outer"></span>
                <span class="caret-inner"></span>
            </div>
            <div class="buttons">
                <button type="button" data-sharing="twitter" class="button">
                    Share on Twitter
                </button>
                <button type="button" data-sharing="google-plus" class="button">
                    Share on Google
                </button>
                <button type="button" data-sharing="facebook" class="button">
                    Share on Facebook
                </button>
                <button type="button" data-sharing="weibo" class="button">
                    Share on Weibo
                </button>
                <button type="button" data-sharing="instapaper" class="button">
                    Share on Instapaper
                </button>
            </div>
        </div>
    </div>
    

    
    <a href="#" target="_blank" class="btn pull-right google-plus-sharing-link sharing-link" data-sharing="google-plus" aria-label="Google"><i class="fa fa-google-plus"></i></a>
    
    
    <a href="#" target="_blank" class="btn pull-right facebook-sharing-link sharing-link" data-sharing="facebook" aria-label="Facebook"><i class="fa fa-facebook"></i></a>
    
    
    <a href="#" target="_blank" class="btn pull-right twitter-sharing-link sharing-link" data-sharing="twitter" aria-label="Twitter"><i class="fa fa-twitter"></i></a>
    
    
    


    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../../" >Redux 中文文档 Join the chat at https://gitter.im/camsong/redux-in-chinese</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <a id="edit-link" href="https://github.com/camsong/redux-in-chinese/tree/master/docs/api/Store.md" class="btn fa fa-edit pull-left">&#xA0;&#xA0;&#x5F00;&#x59CB;&#x7EA0;&#x9519;</a><h1 id="store">Store</h1>
<p>Store &#x5C31;&#x662F;&#x7528;&#x6765;&#x7EF4;&#x6301;&#x5E94;&#x7528;&#x6240;&#x6709;&#x7684; <a href="../Glossary.html#state">state &#x6811;</a> &#x7684;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x3002;
&#x6539;&#x53D8; store &#x5185; state &#x7684;&#x60DF;&#x4E00;&#x9014;&#x5F84;&#x662F;&#x5BF9;&#x5B83; dispatch &#x4E00;&#x4E2A; <a href="../Glossary.html#action">action</a>&#x3002;</p>
<p>Store &#x4E0D;&#x662F;&#x7C7B;&#x3002;&#x5B83;&#x53EA;&#x662F;&#x6709;&#x51E0;&#x4E2A;&#x65B9;&#x6CD5;&#x7684;&#x5BF9;&#x8C61;&#x3002;
&#x8981;&#x521B;&#x5EFA;&#x5B83;&#xFF0C;&#x53EA;&#x9700;&#x8981;&#x628A;&#x6839;&#x90E8;&#x7684; <a href="../Glossary.html#reducer">reducing &#x51FD;&#x6570;</a> &#x4F20;&#x9012;&#x7ED9; <a href="createStore.html"><code>createStore</code></a>&#x3002;</p>
<blockquote>
<h5 id="flux-%E7%94%A8%E6%88%B7%E4%BD%BF%E7%94%A8%E6%B3%A8%E6%84%8F">Flux &#x7528;&#x6237;&#x4F7F;&#x7528;&#x6CE8;&#x610F;</h5>
<p>&#x5982;&#x679C;&#x4F60;&#x4EE5;&#x524D;&#x4F7F;&#x7528; Flux&#xFF0C;&#x90A3;&#x4E48;&#x4F60;&#x53EA;&#x9700;&#x8981;&#x6CE8;&#x610F;&#x4E00;&#x4E2A;&#x91CD;&#x8981;&#x7684;&#x533A;&#x522B;&#x3002;Redux &#x6CA1;&#x6709; Dispatcher &#x4E14;&#x4E0D;&#x652F;&#x6301;&#x591A;&#x4E2A; store&#x3002;&#x76F8;&#x53CD;&#xFF0C;&#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x5355;&#x4E00;&#x7684; store &#x548C;&#x4E00;&#x4E2A;&#x6839;&#x7EA7;&#x7684; reduce &#x51FD;&#x6570;&#xFF08;reducer&#xFF09;&#x3002;&#x968F;&#x7740;&#x5E94;&#x7528;&#x4E0D;&#x65AD;&#x53D8;&#x5927;&#xFF0C;&#x4F60;&#x5E94;&#x8BE5;&#x628A;&#x6839;&#x7EA7;&#x7684; reducer &#x62C6;&#x6210;&#x591A;&#x4E2A;&#x5C0F;&#x7684; reducers&#xFF0C;&#x5206;&#x522B;&#x72EC;&#x7ACB;&#x5730;&#x64CD;&#x4F5C; state &#x6811;&#x7684;&#x4E0D;&#x540C;&#x90E8;&#x5206;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x6DFB;&#x52A0;&#x65B0;&#x7684; stores&#x3002;&#x8FD9;&#x5C31;&#x50CF;&#x4E00;&#x4E2A; React &#x5E94;&#x7528;&#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x6839;&#x7EA7;&#x7684;&#x7EC4;&#x4EF6;&#xFF0C;&#x8FD9;&#x4E2A;&#x6839;&#x7EC4;&#x4EF6;&#x53C8;&#x7531;&#x5F88;&#x591A;&#x5C0F;&#x7EC4;&#x4EF6;&#x6784;&#x6210;&#x3002;</p>
</blockquote>
<h3 id="store-%E6%96%B9%E6%B3%95">Store &#x65B9;&#x6CD5;</h3>
<ul>
<li><a href="#getState"><code><span class="token function">getState</span><span class="token punctuation">(</span><span class="token punctuation">)</span></code></a></li>
<li><a href="#dispatch"><code><span class="token function">dispatch</span><span class="token punctuation">(</span>action<span class="token punctuation">)</span></code></a></li>
<li><a href="#subscribe"><code><span class="token function">subscribe</span><span class="token punctuation">(</span>listener<span class="token punctuation">)</span></code></a></li>
<li><a href="#replaceReducer"><code><span class="token function">replaceReducer</span><span class="token punctuation">(</span>nextReducer<span class="token punctuation">)</span></code></a></li>
</ul>
<h2 id="store-%E6%96%B9%E6%B3%95">Store &#x65B9;&#x6CD5;</h2>
<h3 id="-a-id-getstate-a-getstate-getstate"><a id="getState"></a><a href="#getState"><code><span class="token function">getState</span><span class="token punctuation">(</span><span class="token punctuation">)</span></code></a></h3>
<p>&#x8FD4;&#x56DE;&#x5E94;&#x7528;&#x5F53;&#x524D;&#x7684; state &#x6811;&#x3002;<br>&#x5B83;&#x4E0E; store &#x7684;&#x6700;&#x540E;&#x4E00;&#x4E2A; reducer &#x8FD4;&#x56DE;&#x503C;&#x76F8;&#x540C;&#x3002;</p>
<h4 id="%E8%BF%94%E5%9B%9E%E5%80%BC">&#x8FD4;&#x56DE;&#x503C;</h4>
<p><em>(any)</em>: &#x5E94;&#x7528;&#x5F53;&#x524D;&#x7684; state &#x6811;&#x3002;</p>
<hr>

<h3 id="-a-id-dispatch-a-dispatch-action-dispatch"><a id="dispatch"></a><a href="#dispatch"><code><span class="token function">dispatch</span><span class="token punctuation">(</span>action<span class="token punctuation">)</span></code></a></h3>
<p>&#x5206;&#x53D1; action&#x3002;&#x8FD9;&#x662F;&#x89E6;&#x53D1; state &#x53D8;&#x5316;&#x7684;&#x60DF;&#x4E00;&#x9014;&#x5F84;&#x3002;</p>
<p>&#x4F1A;&#x4F7F;&#x7528;&#x5F53;&#x524D; <a href="#getState"><code><span class="token function">getState</span><span class="token punctuation">(</span><span class="token punctuation">)</span></code></a> &#x7684;&#x7ED3;&#x679C;&#x548C;&#x4F20;&#x5165;&#x7684; <code>action</code> &#x4EE5;&#x540C;&#x6B65;&#x65B9;&#x5F0F;&#x7684;&#x8C03;&#x7528; store &#x7684; reduce &#x51FD;&#x6570;&#x3002;&#x8FD4;&#x56DE;&#x503C;&#x4F1A;&#x88AB;&#x4F5C;&#x4E3A;&#x4E0B;&#x4E00;&#x4E2A; state&#x3002;&#x4ECE;&#x73B0;&#x5728;&#x5F00;&#x59CB;&#xFF0C;&#x8FD9;&#x5C31;&#x6210;&#x4E3A;&#x4E86; <a href="#getState"><code><span class="token function">getState</span><span class="token punctuation">(</span><span class="token punctuation">)</span></code></a> &#x7684;&#x8FD4;&#x56DE;&#x503C;&#xFF0C;&#x540C;&#x65F6;&#x53D8;&#x5316;&#x76D1;&#x542C;&#x5668;(change listener)&#x4F1A;&#x88AB;&#x89E6;&#x53D1;&#x3002;</p>
<blockquote>
<h5 id="flux-%E7%94%A8%E6%88%B7%E4%BD%BF%E7%94%A8%E6%B3%A8%E6%84%8F">Flux &#x7528;&#x6237;&#x4F7F;&#x7528;&#x6CE8;&#x610F;</h5>
<p>&#x5F53;&#x4F60;&#x5728; <a href="../Glossary.html#reducer">reducer</a> &#x5185;&#x90E8;&#x8C03;&#x7528; <code>dispatch</code> &#x65F6;&#xFF0C;&#x5C06;&#x4F1A;&#x629B;&#x51FA;&#x9519;&#x8BEF;&#x63D0;&#x793A;&#x201C;Reducers may not dispatch actions.&#xFF08;Reducer &#x5185;&#x4E0D;&#x80FD; dispatch action&#xFF09;&#x201D;&#x3002;&#x8FD9;&#x5C31;&#x76F8;&#x5F53;&#x4E8E; Flux &#x91CC;&#x7684; &#x201C;Cannot dispatch in a middle of dispatch&#xFF08;dispatch &#x8FC7;&#x7A0B;&#x4E2D;&#x4E0D;&#x80FD;&#x518D; dispatch&#xFF09;&#x201D;&#xFF0C;&#x4F46;&#x5E76;&#x4E0D;&#x4F1A;&#x5F15;&#x8D77;&#x5BF9;&#x5E94;&#x7684;&#x9519;&#x8BEF;&#x3002;&#x5728; Flux &#x91CC;&#xFF0C;&#x5F53; Store &#x5904;&#x7406; action &#x548C;&#x89E6;&#x53D1; update &#x4E8B;&#x4EF6;&#x65F6;&#xFF0C;dispatch &#x662F;&#x7981;&#x6B62;&#x7684;&#x3002;&#x8FD9;&#x4E2A;&#x9650;&#x5236;&#x5E76;&#x4E0D;&#x597D;&#xFF0C;&#x56E0;&#x4E3A;&#x4ED6;&#x9650;&#x5236;&#x4E86;&#x4E0D;&#x80FD;&#x5728;&#x751F;&#x547D;&#x5468;&#x671F;&#x56DE;&#x8C03;&#x91CC; dispatch action&#xFF0C;&#x8FD8;&#x6709;&#x5176;&#x5B83;&#x4E00;&#x4E9B;&#x672C;&#x6765;&#x5F88;&#x6B63;&#x5E38;&#x7684;&#x5730;&#x65B9;&#x3002;</p>
<p>&#x5728; Redux &#x91CC;&#xFF0C;&#x53EA;&#x4F1A;&#x5728;&#x6839; reducer &#x8FD4;&#x56DE;&#x65B0; state &#x7ED3;&#x675F;&#x540E;&#x518D;&#x4F1A;&#x8C03;&#x7528;&#x4E8B;&#x4EF6;&#x76D1;&#x542C;&#x5668;&#xFF0C;&#x56E0;&#x6B64;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x5728;&#x4E8B;&#x4EF6;&#x76D1;&#x542C;&#x5668;&#x91CC;&#x518D;&#x505A; dispatch&#x3002;&#x60DF;&#x4E00;&#x4F7F;&#x4F60;&#x4E0D;&#x80FD;&#x5728; reducer &#x4E2D;&#x9014; dispatch &#x7684;&#x539F;&#x56E0;&#x662F;&#x8981;&#x786E;&#x4FDD; reducer &#x6CA1;&#x6709;&#x526F;&#x4F5C;&#x7528;&#x3002;&#x5982;&#x679C; action &#x5904;&#x7406;&#x4F1A;&#x4EA7;&#x751F;&#x526F;&#x4F5C;&#x7528;&#xFF0C;&#x6B63;&#x786E;&#x7684;&#x505A;&#x6CD5;&#x662F;&#x4F7F;&#x7528;&#x5F02;&#x6B65; <a href="../Glossary.html#action-creator">action &#x521B;&#x5EFA;&#x51FD;&#x6570;</a>&#x3002;</p>
</blockquote>
<h4 id="%E5%8F%82%E6%95%B0">&#x53C2;&#x6570;</h4>
<ol>
<li><code>action</code> (<em>Object</em><sup>&#x2020;</sup>): &#x63CF;&#x8FF0;&#x5E94;&#x7528;&#x53D8;&#x5316;&#x7684;&#x666E;&#x901A;&#x5BF9;&#x8C61;&#x3002;Action &#x662F;&#x628A;&#x6570;&#x636E;&#x4F20;&#x5165; store &#x7684;&#x60DF;&#x4E00;&#x9014;&#x5F84;&#xFF0C;&#x6240;&#x4EE5;&#x4EFB;&#x4F55;&#x6570;&#x636E;&#xFF0C;&#x65E0;&#x8BBA;&#x6765;&#x81EA; UI &#x4E8B;&#x4EF6;&#xFF0C;&#x7F51;&#x7EDC;&#x56DE;&#x8C03;&#x6216;&#x8005;&#x662F;&#x5176;&#x5B83;&#x8D44;&#x6E90;&#x5982; WebSockets&#xFF0C;&#x6700;&#x7EC8;&#x90FD;&#x5E94;&#x8BE5;&#x4EE5; action &#x7684;&#x5F62;&#x5F0F;&#x88AB; dispatch&#x3002;&#x6309;&#x7167;&#x7EA6;&#x5B9A;&#xFF0C;action &#x5177;&#x6709; <code>type</code> &#x5B57;&#x6BB5;&#x6765;&#x8868;&#x793A;&#x5B83;&#x7684;&#x7C7B;&#x578B;&#x3002;type &#x4E5F;&#x53EF;&#x88AB;&#x5B9A;&#x4E49;&#x4E3A;&#x5E38;&#x91CF;&#x6216;&#x8005;&#x662F;&#x4ECE;&#x5176;&#x5B83;&#x6A21;&#x5757;&#x5F15;&#x5165;&#x3002;&#x6700;&#x597D;&#x4F7F;&#x7528;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x800C;&#x4E0D;&#x662F; <a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Symbol" target="_blank">Symbols</a> &#x4F5C;&#x4E3A; action&#xFF0C;&#x56E0;&#x4E3A;&#x5B57;&#x7B26;&#x4E32;&#x662F;&#x53EF;&#x4EE5;&#x88AB;&#x5E8F;&#x5217;&#x5316;&#x7684;&#x3002;&#x9664;&#x4E86; <code>type</code> &#x5B57;&#x6BB5;&#x5916;&#xFF0C;action &#x5BF9;&#x8C61;&#x7684;&#x7ED3;&#x6784;&#x5B8C;&#x5168;&#x53D6;&#x51B3;&#x4E8E;&#x4F60;&#x3002;&#x53C2;&#x7167; <a href="https://github.com/acdlite/flux-standard-action" target="_blank">Flux &#x6807;&#x51C6; Action</a> &#x83B7;&#x53D6;&#x5982;&#x4F55;&#x7EC4;&#x7EC7; action &#x7684;&#x5EFA;&#x8BAE;&#x3002;</li>
</ol>
<h4 id="%E8%BF%94%E5%9B%9E%E5%80%BC">&#x8FD4;&#x56DE;&#x503C;</h4>
<p>(Object<sup>&#x2020;</sup>): &#x8981; dispatch &#x7684; action&#x3002;</p>
<h4 id="%E6%B3%A8%E6%84%8F">&#x6CE8;&#x610F;</h4>
<p><sup>&#x2020;</sup> &#x4F7F;&#x7528; <a href="createStore.html"><code>createStore</code></a> &#x521B;&#x5EFA;&#x7684; &#x201C;&#x7EAF;&#x6B63;&#x201D; store &#x53EA;&#x652F;&#x6301;&#x666E;&#x901A;&#x5BF9;&#x8C61;&#x7C7B;&#x578B;&#x7684; action&#xFF0C;&#x800C;&#x4E14;&#x4F1A;&#x7ACB;&#x5373;&#x4F20;&#x5230; reducer &#x6765;&#x6267;&#x884C;&#x3002;</p>
<p>&#x4F46;&#x662F;&#xFF0C;&#x5982;&#x679C;&#x4F60;&#x7528; <a href="applyMiddleware.html"><code>applyMiddleware</code></a> &#x6765;&#x5957;&#x4F4F; <a href="createStore.html"><code>createStore</code></a> &#x65F6;&#xFF0C;middleware &#x53EF;&#x4EE5;&#x4FEE;&#x6539; action &#x7684;&#x6267;&#x884C;&#xFF0C;&#x5E76;&#x652F;&#x6301;&#x6267;&#x884C; dispatch <a href="../Glossary.html#intent">intent&#xFF08;&#x610F;&#x56FE;&#xFF09;</a>&#x3002;Intent &#x4E00;&#x822C;&#x662F;&#x5F02;&#x6B65;&#x64CD;&#x4F5C;&#x5982; Promise&#x3001;Observable &#x6216;&#x8005; Thunk&#x3002;</p>
<p>Middleware &#x662F;&#x7531;&#x793E;&#x533A;&#x521B;&#x5EFA;&#xFF0C;&#x5E76;&#x4E0D;&#x4F1A;&#x540C; Redux &#x4E00;&#x8D77;&#x53D1;&#x884C;&#x3002;&#x4F60;&#x9700;&#x8981;&#x624B;&#x52A8;&#x5B89;&#x88C5; <a href="https://github.com/gaearon/redux-thunk" target="_blank">redux-thunk</a> &#x6216;&#x8005; <a href="https://github.com/acdlite/redux-promise" target="_blank">redux-promise</a> &#x5E93;&#x3002;&#x4F60;&#x4E5F;&#x53EF;&#x4EE5;&#x521B;&#x5EFA;&#x81EA;&#x5DF1;&#x7684; middleware&#x3002;</p>
<p>&#x60F3;&#x5B66;&#x4E60;&#x5982;&#x4F55;&#x63CF;&#x8FF0;&#x5F02;&#x6B65; API &#x8C03;&#x7528;&#xFF1F;&#x770B;&#x4E00;&#x4E0B; action &#x521B;&#x5EFA;&#x51FD;&#x6570;&#x91CC;&#x5F53;&#x524D;&#x7684; state&#xFF0C;&#x6267;&#x884C;&#x4E00;&#x4E2A;&#x6709;&#x526F;&#x4F5C;&#x7528;&#x7684;&#x64CD;&#x4F5C;&#xFF0C;&#x6216;&#x8005;&#x4EE5;&#x94FE;&#x5F0F;&#x64CD;&#x4F5C;&#x6267;&#x884C;&#x5B83;&#x4EEC;&#xFF0C;&#x53C2;&#x7167; <a href="applyMiddleware.html"><code>applyMiddleware</code></a> &#x4E2D;&#x7684;&#x793A;&#x4F8B;&#x3002;</p>
<h4 id="%E7%A4%BA%E4%BE%8B">&#x793A;&#x4F8B;</h4>
<pre><code class="lang-js"><span class="token keyword">import</span> <span class="token punctuation">{</span> createStore <span class="token punctuation">}</span> from <span class="token string">&apos;redux&apos;</span>
<span class="token keyword">let</span> store <span class="token operator">=</span> <span class="token function">createStore</span><span class="token punctuation">(</span>todos<span class="token punctuation">,</span> <span class="token punctuation">[</span> <span class="token string">&apos;Use Redux&apos;</span> <span class="token punctuation">]</span><span class="token punctuation">)</span>

<span class="token keyword">function</span> <span class="token function">addTodo</span><span class="token punctuation">(</span>text<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token punctuation">{</span>
    type<span class="token punctuation">:</span> <span class="token string">&apos;ADD_TODO&apos;</span><span class="token punctuation">,</span>
    text
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

store<span class="token punctuation">.</span><span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token function">addTodo</span><span class="token punctuation">(</span><span class="token string">&apos;Read the docs&apos;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
store<span class="token punctuation">.</span><span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token function">addTodo</span><span class="token punctuation">(</span><span class="token string">&apos;Read about the middleware&apos;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre>
<hr>

<h3 id="-a-id-subscribe-a-subscribe-listener-subscribe"><a id="subscribe"></a><a href="#subscribe"><code><span class="token function">subscribe</span><span class="token punctuation">(</span>listener<span class="token punctuation">)</span></code></a></h3>
<p>&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;&#x53D8;&#x5316;&#x76D1;&#x542C;&#x5668;&#x3002;&#x6BCF;&#x5F53; dispatch action &#x7684;&#x65F6;&#x5019;&#x5C31;&#x4F1A;&#x6267;&#x884C;&#xFF0C;state &#x6811;&#x4E2D;&#x7684;&#x4E00;&#x90E8;&#x5206;&#x53EF;&#x80FD;&#x5DF2;&#x7ECF;&#x53D8;&#x5316;&#x3002;&#x4F60;&#x53EF;&#x4EE5;&#x5728;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x91CC;&#x8C03;&#x7528; <a href="#getState"><code><span class="token function">getState</span><span class="token punctuation">(</span><span class="token punctuation">)</span></code></a> &#x6765;&#x62FF;&#x5230;&#x5F53;&#x524D; state&#x3002;</p>
<p>&#x4F60;&#x53EF;&#x4EE5;&#x5728;&#x53D8;&#x5316;&#x76D1;&#x542C;&#x5668;&#x91CC;&#x9762;&#x8FDB;&#x884C; <a href="#dispatch"><code><span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token punctuation">)</span></code></a>&#xFF0C;&#x4F46;&#x4F60;&#x9700;&#x8981;&#x6CE8;&#x610F;&#x4E0B;&#x9762;&#x7684;&#x4E8B;&#x9879;&#xFF1A;</p>
<ol>
<li>&#x76D1;&#x542C;&#x5668;&#x8C03;&#x7528; <a href="#dispatch"><code><span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token punctuation">)</span></code></a> &#x4EC5;&#x4EC5;&#x5E94;&#x5F53;&#x53D1;&#x751F;&#x5728;&#x54CD;&#x5E94;&#x7528;&#x6237;&#x7684; actions &#x6216;&#x8005;&#x7279;&#x6B8A;&#x7684;&#x6761;&#x4EF6;&#x9650;&#x5236;&#x4E0B;&#xFF08;&#x6BD4;&#x5982;&#xFF1A; &#x5728; store &#x6709;&#x4E00;&#x4E2A;&#x7279;&#x6B8A;&#x7684;&#x5B57;&#x6BB5;&#x65F6; dispatch action&#xFF09;&#x3002;&#x867D;&#x7136;&#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x6761;&#x4EF6;&#x53BB;&#x8C03;&#x7528; <a href="#dispatch"><code><span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token punctuation">)</span></code></a> &#x5728;&#x6280;&#x672F;&#x4E0A;&#x662F;&#x53EF;&#x884C;&#x7684;&#xFF0C;&#x4F46;&#x662F;&#x968F;&#x7740;&#x6BCF;&#x6B21; <a href="#dispatch"><code><span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token punctuation">)</span></code></a> &#x6539;&#x53D8; store &#x53EF;&#x80FD;&#x4F1A;&#x5BFC;&#x81F4;&#x9677;&#x5165;&#x65E0;&#x7A77;&#x7684;&#x5FAA;&#x73AF;&#x3002;</li>
<li>&#x8BA2;&#x9605;&#x5668;&#xFF08;subscriptions&#xFF09; &#x5728;&#x6BCF;&#x6B21; <a href="#dispatch"><code><span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token punctuation">)</span></code></a> &#x8C03;&#x7528;&#x4E4B;&#x524D;&#x90FD;&#x4F1A;&#x4FDD;&#x5B58;&#x4E00;&#x4EFD;&#x5FEB;&#x7167;&#x3002;&#x5F53;&#x4F60;&#x5728;&#x6B63;&#x5728;&#x8C03;&#x7528;&#x76D1;&#x542C;&#x5668;&#xFF08;listener&#xFF09;&#x7684;&#x65F6;&#x5019;&#x8BA2;&#x9605;(subscribe)&#x6216;&#x8005;&#x53BB;&#x6389;&#x8BA2;&#x9605;&#xFF08;unsubscribe&#xFF09;&#xFF0C;&#x5BF9;&#x5F53;&#x524D;&#x7684; <a href="#dispatch"><code><span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token punctuation">)</span></code></a> &#x4E0D;&#x4F1A;&#x6709;&#x4EFB;&#x4F55;&#x5F71;&#x54CD;&#x3002;&#x4F46;&#x662F;&#x5BF9;&#x4E8E;&#x4E0B;&#x4E00;&#x6B21;&#x7684; <a href="#dispatch"><code><span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token punctuation">)</span></code></a>&#xFF0C;&#x65E0;&#x8BBA;&#x5D4C;&#x5957;&#x4E0E;&#x5426;&#xFF0C;&#x90FD;&#x4F1A;&#x4F7F;&#x7528;&#x8BA2;&#x9605;&#x5217;&#x8868;&#x91CC;&#x6700;&#x8FD1;&#x7684;&#x4E00;&#x6B21;&#x5FEB;&#x7167;&#x3002;</li>
<li>&#x8BA2;&#x9605;&#x5668;&#x4E0D;&#x5E94;&#x8BE5;&#x6CE8;&#x610F;&#x5230;&#x6240;&#x6709; state &#x7684;&#x53D8;&#x5316;&#xFF0C;&#x5728;&#x8BA2;&#x9605;&#x5668;&#x88AB;&#x8C03;&#x7528;&#x4E4B;&#x524D;&#xFF0C;&#x5F80;&#x5F80;&#x7531;&#x4E8E;&#x5D4C;&#x5957;&#x7684; <a href="#dispatch"><code><span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token punctuation">)</span></code></a> &#x5BFC;&#x81F4; state &#x53D1;&#x751F;&#x591A;&#x6B21;&#x7684;&#x6539;&#x53D8;&#x3002;&#x4FDD;&#x8BC1;&#x6240;&#x6709;&#x7684;&#x76D1;&#x542C;&#x5668;&#x90FD;&#x6CE8;&#x518C;&#x5728; <a href="#dispatch"><code><span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token punctuation">)</span></code></a> &#x542F;&#x52A8;&#x4E4B;&#x524D;&#xFF0C;&#x8FD9;&#x6837;&#xFF0C;&#x5728;&#x8C03;&#x7528;&#x76D1;&#x542C;&#x5668;&#x7684;&#x65F6;&#x5019;&#x5C31;&#x4F1A;&#x4F20;&#x5165;&#x76D1;&#x542C;&#x5668;&#x6240;&#x5B58;&#x5728;&#x65F6;&#x95F4;&#x91CC;&#x6700;&#x65B0;&#x7684;&#x4E00;&#x6B21; state&#x3002;</li>
</ol>
<p>&#x8FD9;&#x662F;&#x4E00;&#x4E2A;&#x5E95;&#x5C42; API&#x3002;&#x591A;&#x6570;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x4F60;&#x4E0D;&#x4F1A;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x5B83;&#xFF0C;&#x4F1A;&#x4F7F;&#x7528;&#x4E00;&#x4E9B; React&#xFF08;&#x6216;&#x5176;&#x5B83;&#x5E93;&#xFF09;&#x7684;&#x7ED1;&#x5B9A;&#x3002;&#x5982;&#x679C;&#x4F60;&#x60F3;&#x8BA9;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x6267;&#x884C;&#x7684;&#x65F6;&#x5019;&#x4F7F;&#x7528;&#x5F53;&#x524D;&#x7684; state&#xFF0C;&#x4F60;&#x53EF;&#x4EE5; <a href="https://github.com/rackt/redux/issues/303#issuecomment-125184409" target="_blank">&#x628A; store &#x8F6C;&#x6362;&#x6210;&#x4E00;&#x4E2A; Observable &#x6216;&#x8005;&#x5199;&#x4E00;&#x4E2A;&#x5B9A;&#x5236;&#x7684; <code>observeStore</code> &#x5DE5;&#x5177;</a>&#x3002;</p>
<p>&#x5982;&#x679C;&#x9700;&#x8981;&#x89E3;&#x7ED1;&#x8FD9;&#x4E2A;&#x53D8;&#x5316;&#x76D1;&#x542C;&#x5668;&#xFF0C;&#x6267;&#x884C; <code>subscribe</code> &#x8FD4;&#x56DE;&#x7684;&#x51FD;&#x6570;&#x5373;&#x53EF;&#x3002;</p>
<h4 id="%E5%8F%82%E6%95%B0">&#x53C2;&#x6570;</h4>
<ol>
<li><code>listener</code> (<em>Function</em>): &#x6BCF;&#x5F53; dispatch action &#x7684;&#x65F6;&#x5019;&#x90FD;&#x4F1A;&#x6267;&#x884C;&#x7684;&#x56DE;&#x8C03;&#x3002;state &#x6811;&#x4E2D;&#x7684;&#x4E00;&#x90E8;&#x5206;&#x53EF;&#x80FD;&#x5DF2;&#x7ECF;&#x53D8;&#x5316;&#x3002;&#x4F60;&#x53EF;&#x4EE5;&#x5728;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x91CC;&#x8C03;&#x7528; <a href="#getState"><code><span class="token function">getState</span><span class="token punctuation">(</span><span class="token punctuation">)</span></code></a> &#x6765;&#x62FF;&#x5230;&#x5F53;&#x524D; state&#x3002;store &#x7684; reducer &#x5E94;&#x8BE5;&#x662F;&#x7EAF;&#x51FD;&#x6570;&#xFF0C;&#x56E0;&#x6B64;&#x4F60;&#x53EF;&#x80FD;&#x9700;&#x8981;&#x5BF9; state &#x6811;&#x4E2D;&#x7684;&#x5F15;&#x7528;&#x505A;&#x6DF1;&#x5EA6;&#x6BD4;&#x8F83;&#x6765;&#x786E;&#x5B9A;&#x5B83;&#x7684;&#x503C;&#x662F;&#x5426;&#x6709;&#x53D8;&#x5316;&#x3002;</li>
</ol>
<h5 id="%E8%BF%94%E5%9B%9E%E5%80%BC">&#x8FD4;&#x56DE;&#x503C;</h5>
<p>(<em>Function</em>): &#x4E00;&#x4E2A;&#x53EF;&#x4EE5;&#x89E3;&#x7ED1;&#x53D8;&#x5316;&#x76D1;&#x542C;&#x5668;&#x7684;&#x51FD;&#x6570;&#x3002;</p>
<h5 id="%E7%A4%BA%E4%BE%8B">&#x793A;&#x4F8B;</h5>
<pre><code class="lang-js"><span class="token keyword">function</span> <span class="token function">select</span><span class="token punctuation">(</span>state<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> state<span class="token punctuation">.</span>some<span class="token punctuation">.</span>deep<span class="token punctuation">.</span>property
<span class="token punctuation">}</span>

<span class="token keyword">let</span> currentValue
<span class="token keyword">function</span> <span class="token function">handleChange</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">let</span> previousValue <span class="token operator">=</span> currentValue
  currentValue <span class="token operator">=</span> <span class="token function">select</span><span class="token punctuation">(</span>store<span class="token punctuation">.</span><span class="token function">getState</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>

  <span class="token keyword">if</span> <span class="token punctuation">(</span>previousValue <span class="token operator">!</span><span class="token operator">==</span> currentValue<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&apos;Some deep nested property changed from&apos;</span><span class="token punctuation">,</span> previousValue<span class="token punctuation">,</span> <span class="token string">&apos;to&apos;</span><span class="token punctuation">,</span> currentValue<span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">let</span> unsubscribe <span class="token operator">=</span> store<span class="token punctuation">.</span><span class="token function">subscribe</span><span class="token punctuation">(</span>handleChange<span class="token punctuation">)</span>
<span class="token function">unsubscribe</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre>
<hr>

<h3 id="-a-id-replacereducer-a-replacereducer-nextreducer-replacereducer"><a id="replaceReducer"></a><a href="#replaceReducer"><code><span class="token function">replaceReducer</span><span class="token punctuation">(</span>nextReducer<span class="token punctuation">)</span></code></a></h3>
<p>&#x66FF;&#x6362; store &#x5F53;&#x524D;&#x7528;&#x6765;&#x8BA1;&#x7B97; state &#x7684; reducer&#x3002;</p>
<p>&#x8FD9;&#x662F;&#x4E00;&#x4E2A;&#x9AD8;&#x7EA7; API&#x3002;&#x53EA;&#x6709;&#x5728;&#x4F60;&#x9700;&#x8981;&#x5B9E;&#x73B0;&#x4EE3;&#x7801;&#x5206;&#x9694;&#xFF0C;&#x800C;&#x4E14;&#x9700;&#x8981;&#x7ACB;&#x5373;&#x52A0;&#x8F7D;&#x4E00;&#x4E9B; reducer &#x7684;&#x65F6;&#x5019;&#x624D;&#x53EF;&#x80FD;&#x4F1A;&#x7528;&#x5230;&#x5B83;&#x3002;&#x5728;&#x5B9E;&#x73B0; Redux &#x70ED;&#x52A0;&#x8F7D;&#x673A;&#x5236;&#x7684;&#x65F6;&#x5019;&#x4E5F;&#x53EF;&#x80FD;&#x4F1A;&#x7528;&#x5230;&#x3002;</p>
<h4 id="%E5%8F%82%E6%95%B0">&#x53C2;&#x6570;</h4>
<ol>
<li><code>reducer</code> (<em>Function</em>) store &#x4F1A;&#x4F7F;&#x7528;&#x7684;&#x4E0B;&#x4E00;&#x4E2A; reducer&#x3002;</li>
</ol>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../../docs/api/createStore.html" class="navigation navigation-prev " aria-label="Previous page: createStore"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../../docs/api/combineReducers.html" class="navigation navigation-next " aria-label="Next page: combineReducers"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../../gitbook/app.js"></script>

    
    <script src="../../gitbook/plugins/gitbook-plugin-edit-link/plugin.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-ga/plugin.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"fontSettings":{"theme":null,"family":"sans","size":2},"edit-link":{"base":"https://github.com/camsong/redux-in-chinese/tree/master","label":"开始纠错"},"ga":{"token":"UA-66122997-1","configuration":"auto"}};
    gitbook.start(config);
});
</script>

        <script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-66122997-1', 'auto');ga('send', 'pageview');</script>
    </body>
    
</html>
